package com.mths.server.entity;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

@Entity
@SQLDelete(sql = "update DOCUMENT_META_DATA set status='P' where objid=?")
@Where(clause = "status='A'")
@Table(name = "DOCUMENT_META_DATA")
public class DocumentMetaData extends AbstractEntity {

	@Where(clause = "status='A'")
	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "DOCUMENT_TYPE_OID")
	private DocumentType documentType;

	@Where(clause = "status='A'")
	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "META_DATA_OID")
	private MetaData metaData;

	public DocumentMetaData(DocumentType documentType, MetaData metaData) {
		super();
		this.documentType = documentType;
		this.metaData = metaData;
	}

	public DocumentMetaData() {
		super();
	}

	public DocumentType getDocumentType() {
		return documentType;
	}

	public void setDocumentType(DocumentType documentType) {
		this.documentType = documentType;
	}

	public MetaData getMetaData() {
		return metaData;
	}

	public void setMetaData(MetaData metaData) {
		this.metaData = metaData;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((documentType == null) ? 0 : documentType.hashCode());
		result = prime * result + ((metaData == null) ? 0 : metaData.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		DocumentMetaData other = (DocumentMetaData) obj;
		if (documentType == null) {
			if (other.documentType != null)
				return false;
		} else if (!documentType.equals(other.documentType))
			return false;
		if (metaData == null) {
			if (other.metaData != null)
				return false;
		} else if (!metaData.equals(other.metaData))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "DocumentMetaData [documentType=" + documentType + ", metaData=" + metaData + "]";
	}

}